package com.thti.mecool.client.activity;

import java.util.ArrayList;
import java.util.List;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ImageButton;
import android.widget.ListView;

import com.thti.mecool.client.adapter.PlanListViewAdapter;
import com.thti.mecool.client.base.BaseActivity;
import com.thti.mecool.client.base.Cache;
import com.thti.mecool.client.model.biz.PlanBizImpl;
import com.thti.mecool.client.model.po.PlanCategory;
import com.thti.mecool.client.widget.Toolbar;

public class PlanActivity extends BaseActivity {
	
	private ListView planListView;
	private PlanBizImpl planBizImpl;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		Cache.add(this);
		this.noTitle();
		setContentView(R.layout.mecool_plan);
		 initToolbar();
		planListView=(ListView)findViewById(R.id.mecool_plan_list);
		planBizImpl=new PlanBizImpl(this);
		List<PlanCategory> list=new ArrayList<PlanCategory>();
		for (int i = 0; i < 3; i++) {
			PlanCategory planCategory=new PlanCategory();
			if(i==0){
				planCategory.setCategoryName("新增计划");
				planCategory.setCategoryNumber(0);
			}
			if(i==2){
					planCategory.setCategoryName("草稿箱");
					planCategory.setCategoryNumber(3);
					planCategory.setCount(planBizImpl.findPlanCount(0,String.valueOf(getCurrentUser().getId())));
			}
			if(i==1){
				 	planCategory.setCategoryName("我的计划");
					planCategory.setCategoryNumber(2);
			}
			list.add(planCategory);
		}
		planListView.setAdapter(new PlanListViewAdapter(this, list));
		planListView.setOnItemClickListener(planListViewListener);
	}
	
	private OnItemClickListener planListViewListener=new ListView.OnItemClickListener(){

		@Override
		public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			   Intent intent = new Intent();
			  switch (Integer.parseInt(arg1.getTag().toString())) {
			  	case 0:
					intent.setClass(PlanActivity.this, AddPlanActivity.class);
					startActivity(intent);
			  		break;
				case 1:
					intent.setClass(PlanActivity.this,
							MyPlanActivity.class);
					startActivity(intent);
					break;
				case 2:
					intent.setClass(PlanActivity.this,
							DraftActivity.class);
					startActivity(intent);
					break;
			}
			
		}};
		
		
		private void initToolbar() {
			
			  Toolbar toolbar =new Toolbar(this);
			  toolbar.setToolbarCentreText("计划管理");
			  
			  Toolbar.left_btn.setOnClickListener(onClickListener);
			  Toolbar.hideRightButton();
			  Toolbar.left_btn.setImageResource(R.drawable.mecool_go_back);
		  }
		private OnClickListener onClickListener=new ImageButton.OnClickListener(){

			@Override
			public void onClick(View v) {
				switch (v.getId()) {
				case R.id.mecool_toolbar_leftbtn:
					finish();
					break;
				case R.id.mecool_toolbar_rightbtn:
					Intent intent=new Intent();
					intent.setClass(PlanActivity.this, MakePlanSelectProjectActivity.class);
					startActivity(intent);
					break;
				}
			}};

}
